using Furion.UnifyResult;
using Kevin.Dapr.Actors;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Sckf.Core.Infrastructure;
using Yitter.IdGenerator;

var builder = WebApplication.CreateBuilder(args);
builder.Host.UseNacosConfig(section: "NacosConfig");
builder = builder.Inject();

// Add services to the container.
builder.Services.AddSingleton<RedisHelper>();
builder.Services.AddControllers().AddDapr().AddNewtonsoftJson(options =>
{
    JsonConverter enumConverter = new StringEnumConverter();
    JsonConverter bigintConverter = new BigIntConverter();
    options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
    options.SerializerSettings.ContractResolver = new LowercaseContractResolver();
    options.SerializerSettings.DateFormatString = "yyyy/MM/dd HH:mm:ss";
    options.SerializerSettings.Converters = new[] { enumConverter, bigintConverter };
}).AddInjectWithUnifyResult<RESTfulResultProvider>();

builder.Services.AddActors(options => {
    // 注册Actor
    options.Actors.RegisterActor<SeckillActor>();
});

//注册雪花id生成器
var options = new IdGeneratorOptions(1);
YitIdHelper.SetIdGenerator(options);

var app = builder.Build();

//app.UseNacosConfig(section: "NacosConfig", parser: null, logAction: null);
// Configure the HTTP request pipeline.

//app.UseAuthorization();

// 添加这一行，如果是 MVC和API共存项目，无需添加 string.Empty
app.UseInject("");

app.MapControllers();

// 配置Actor映射处理器
app.MapActorsHandlers();

app.Run();
